package com.bky.jdbc;

import org.springframework.jdbc.core.BatchPreparedStatementSetter;

import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * Created by shipeilei on 2017/5/26.
 */
public class IBatchPreparedStatementSetter implements BatchPreparedStatementSetter{
    private Object[] obj = null;
    private int[] types = null;


    /**
     * 初始化构造器
     * @param types
     * @param param 二维数组
     */
    public IBatchPreparedStatementSetter(int[] types,Object[] param) {
        this.types = types;
        this.obj = param;
    }


    @Override
    public void setValues(PreparedStatement preparedstatement, int i) throws SQLException {
        Object[] temp = (Object[]) obj[i];
        SQLUtil.bindParameters(preparedstatement, types, temp);
    }

    @Override
    public int getBatchSize() {
        if(obj == null)
            return 0;
        return obj.length;
    }
}
